package com.bcx.crm.java.designMode.FactoryMode;

/**
 * Created by ys on 2019/2/19 11:22
 */
public class FactoryModeMain {

    /**
     * 初步优化
     */
    public static void main1(String target){
       TargetExecutor targetExecutor = null;
       if (target.startsWith("AA")){
           targetExecutor = new ExecutorStartWithTag();
       }else if (target.contains("BB")){
           targetExecutor = new ExecutorContainsTag();
       }else {
           System.out.println();
       }
        assert targetExecutor != null;
        targetExecutor.process();
    }

    /**
     * 最后优化
     */
    public static TargetExecutor getExecutor(String target) {
        if (target.startsWith("AA")){
            return new ExecutorStartWithTag();
        }else if (target.contains("BB")){
            return new ExecutorContainsTag();
        }else {
            return null;
        }
    }

    public static void main(String[] args) {
        //初步优化
        main1("AA");
        //最后优化
        TargetExecutor executor = getExecutor("AA");
        if (null != executor){
            executor.process();
        }
    }
}
